package MOLE;

/** 
 Time ��ժҪ˵����
*/
public class Time
{
	public Time()
	{
		//
		// TODO: �ڴ˴���ӹ��캯���߼�
		//
	}

	public static String ConvertSecsToTimeformat(int secs)
	{
	//
		int h = (secs / 3600); //shenhad sije.

		int tmpM = secs % 3600; //shenhad fen
		int m = (tmpM / 60);

		int s = (secs % 60); //shenhad miao
		return ToDoubleFormat(h).toString() + ":" + ToDoubleFormat(m).toString() + ":" + ToDoubleFormat(s).toString();

	}


	public static int CovertTimeToSecs(String hhmmss)
	{

			String [] a = hhmmss.split("[:]", -1);
			int h = Integer.parseInt(a[0]);
			int m = Integer.parseInt(a[1]);
			int s = Integer.parseInt(a[2]);
			int startsecs = h * 3600 + m * 60 + s;
			return startsecs;

	}

	public static String ToDoubleFormat(int i)
	{
		if (String.valueOf(i).length() == 1)
		{
			return "0" + String.valueOf(i);
		}
		else
		{
			return String.valueOf(i);
		}

	}

	public static String GetDate()
	{
		java.time.LocalDateTime d = java.time.LocalDateTime.now();
		String y = GetDouble(d.getYear());
		String m = GetDouble(d.getMonthValue());
		String day = GetDouble(d.getDayOfMonth());
		String s = y + m + day;
		return s;
	}

	public static String GetDate(String span)
	{
		java.time.LocalDateTime d = java.time.LocalDateTime.now();
		String y = GetDouble(d.getYear());
		String m = GetDouble(d.getMonthValue());
		String day = GetDouble(d.getDayOfMonth());
		String s = y + span + m + span + day;
		return s;
	}

	public static String GetDate(java.time.LocalDateTime d, String span)
	{
		//DateTime d=DateTime.Now;

		String y = GetDouble(d.getYear());
		String m = GetDouble(d.getMonthValue());
		String day = GetDouble(d.getDayOfMonth());
		String s = y + span + m + span + day;
		return s;
	}

	/** 
	 
	 
	 @param date 20070120>>2007-01-20
	 @param span
	 @return 
	*/
	public static String GetDate(String date, String span)
	{
		//string d=currTerm.Substring(0,8);
		String y = date.substring(0,4);


		String m = date.substring(4, 6);

		String day = date.substring(6, 8);

		String s = y + span + m + span + day;
		return s;
	}

	public static String GetDouble(int i)
	{
		return (i < 10)?"0" + String.valueOf(i):String.valueOf(i);
	}

	public static String AddDate(String yyyymmdd, int i)
	{
		java.time.LocalDateTime d = (java.time.LocalDateTime)MOLE.Time.GetDate(yyyymmdd, "-");
		d = d.plusDays(i);

		return GetDate(d, "");



	}

	public static String getTimeStamp(int length)
	{
		//���17
		String s = java.time.LocalDateTime.now().toString("yyyyMMddHHmmss");
		//string s=DateTime.Now.Millisecond.ToString();
		String ms = java.time.LocalDateTime.now().Millisecond.toString();
	//	ms="56";
		if (ms.length() == 1)
		{
			ms = "00" + ms;
		}
		else if (ms.length() == 2)
		{
			ms = "0" + ms;
		}
		String r = s + ms;
		if (length > 17)
		{
			return r;
		}
		else
		{
			 return r.substring(0,length);
		}
	}

	public static String getMiniTimeStamp()
	{
		int nn = (7 * 365 + 8 * 30 + 9);
		int y = java.time.LocalDateTime.now().getYear();
		int mon = java.time.LocalDateTime.now().getMonthValue();
		int day = java.time.LocalDateTime.now().getDayOfMonth();

		nn = Integer.parseInt(String.valueOf(y).substring(3, 4)) * 365 + mon * 30 + day;
		int h = java.time.LocalDateTime.now().getHour();
		int m = java.time.LocalDateTime.now().getMinute();
		String ns = String.valueOf(nn) + GetDouble(h) + GetDouble(m);
		return ns;
	}
}